package com.woniuxy.common;

import lombok.Data;

/**
 * 封装统一操作结果
 */
@Data
public class Result<T> {
    private Integer code;    //响应编码：1成功 0 表示失败
    private String message; //返回信息
    private T data;         //响应数据

    /**
     * 操作成功：封装信息和数据
     */
    public static <T> Result<T> ok(String message,T data){
        Result<T> result = new Result<>();
        result.data = data;
        result.message = message;
        result.code = 1;
        return result;
    }
    //封装数据
    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.data = data;
        result.code = 1;
        return result;
    }
    //封装信息
    public static <T> Result<T> ok(String message){
        Result<T> result = new Result<>();
        result.message = message;
        result.code = 1;
        return result;
    }
    /**
     * 失败
     */
    public static <T> Result<T> fail(String message) {
        Result<T> result = new Result<>();
        result.message = message;
        result.code = 0;
        return result;
    }
    public static <T> Result<T> fail() {
        Result<T> result = new Result<>();
        result.code = 0;
        return result;
    }
}
